package cn.edu.nuc.film.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.film.common.PageControl;
import cn.edu.nuc.film.common.Pager;
import cn.edu.nuc.film.common.Parameter;
import cn.edu.nuc.film.common.UnitHelper;
import cn.edu.nuc.film.dao.ScreensMapper;
import cn.edu.nuc.film.entity.Screens;
import cn.edu.nuc.film.service.interfaces.ScreensService;

@Service
public class ScreensServiceImpl implements ScreensService {
	
	@Autowired
	private ScreensMapper screensMapper;
	
	/**
	 * 只获取影厅信息
	 */
	public List<Screens> onlyList( int fcId){
		
		List<Screens> screensList = screensMapper.onlyList(fcId);
		return screensList;
		
	}
	
	
	
	
	@Override
	public int addScreens(Screens screens) {
		
		int count = screensMapper.insertSelective(screens);
		return count;
	}

	@Override
	public Pager<Screens> list(PageControl pc,String screensname,int fcId) {
		/**
		 * 设置dao层的参数列表( @Param("start") int start,
		 * @Param("offset") int offset,@Param("filmName") String filmName )
		 */
		Parameter para = new Parameter();
		para.setStart( (pc.getCurrentindex() - 1) * pc.getPagesize());
		para.setOffset( pc.getPagesize());
		para.setName(screensname);
		
		//获取每页的具体数据
		List<Screens> list = screensMapper.selectList( para,fcId );
		
		//设置总记录数
		int pagecount = 0;
		if( screensname != null ){
			pagecount = list.size();
		}else{
			pagecount = screensMapper.count(fcId);
		}
		Pager<Screens> pager = UnitHelper.execlist(pagecount, list, pc);
		return pager;
	}
	
	/**
	 * 获取影厅信息
	 * @param screensid
	 * @return
	 */
	public Screens detail(int screensid){
		Screens screens = screensMapper.selectByPrimaryKey(screensid);
		return screens;
	}
	
	
	/**
	 * 修改影厅信息
	 */
	@Override
	public int updateScreens(Screens screens) {
		int count = screensMapper.updateByPrimaryKeySelective(screens);
		return count;
	}
	
	/**
	 * 删除影厅信息
	 */
	@Override
	public int deleteScreens(int screensid) {
		int count = screensMapper.deleteByPrimaryKey(screensid);
		return count;
	}
	
	
	
	
}
